package com.yunli.mall.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunli.mall.schema.entity.Seckill;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * @author yaolonglong
 * @date 2020/9/20 20:05
 */
@Repository
@Mapper
public interface SeckillMapper extends BaseMapper<Seckill> {
    @Update("update seckill " +
            "set inventory=inventory-1, version=version+1 " +
            "where id=#{id} and version=#{version} and inventory > 0 ")
    int updateUseCAS(Seckill seckill);

    @Update("update seckill " +
            "set inventory=0 " +
            "where id=#{id}")
    void clearInventory(String seckillId);
}
